XN.ListUI = XN.DataBox.extend({
	setList:function(_writeBox,_xPaths){
		this.writeBox = FWK.elementQuery(_writeBox);
		this.xPaths = _xPaths;
		return this;
	},
	$completeData:function(recordArr){
		this.recordArr = recordArr || this.record.selectNodes(this.xPaths.items);
		try{this.$onload();}catch(e){};
		if(this.xPaths.server){
			this.pageSize = parseInt(this.record.selectSingleNode(this.xPaths.pageSize).nodeValue);
			this.page = parseInt(this.record.selectSingleNode(this.xPaths.page).nodeValue);
			this.recordCount = parseInt(this.record.selectSingleNode(this.xPaths.recordCount).nodeValue);
		}
		else{
			this.pageSize = this.xPaths.pageSize || this.recordArr.length;
			this.page = this.xPaths.page || 1;
			this.recordCount = this.recordArr.length;
		}
		this.pageCount = Math.round((this.recordCount / this.pageSize) + (this.pageSize-1)/this.pageSize/2);
		if(this.page>this.pageCount){
			this.page = this.pageCount;
		}
		if(this.page<1){
			this.page = 1;
		}

		if(this.pageUIBox){
			this.writeToPageUI();
		}
		this.writeToList();
	},
	reOrganization:function(_xPaths){
		FWK.extend(this.xPaths,_xPaths);
		this.$completeData();
	},
	setPageUIBox:function(_pageUIBox,_pageX,_pageName){
		this.pageUIBox = FWK.elementQuery(_pageUIBox,"setStyle");
		if(this.pageUIBox){
			this.pageX = FWK.isNum(_pageX)?_pageX:(this.pageX)?this.pageX:10;
		}
		if(this.xPaths.server){
			this.pageName = _pageName;
		}
		return this;
	},
	writeToPageUI:function(){
		if (this.pageCount < 2) {
			this.pageUIBox.setStyle({display:"none"});
			return;
		}
		else{
			this.pageUIBox.setStyle({display:"block"});
		}
		if(this.pageUIBox && FWK.isEl(this.pageUIBox)){
			if(!this.pageUI){
				this.pageUI = this.createPageUI(this.pageUIBox);
				try{this.$pageOk(this.pageUI);}catch(e){}
			}
			else if(this.pageUI.currentPage!=this.page || this.pageUI.totalPage!=this.pageCount){
				this.pageUI.setPagerData(this.pageCount,this.page);

			}
		}
		else if(this.pageUIBox && FWK.isArr(this.pageUIBox)){
			for(var i=0,ilen=this.pageUIBox.length;i<ilen;i+=1){
				if(!this.pageUI)this.pageUI = [];
				if(!this.pageUI[i]){
					this.pageUI[i] = this.createPageUI(this.pageUIBox[i]);
					try{this.$pageOk(this.pageUI[i]);}catch(e){}
				}
				else if(this.pageUI[i].currentPage!=this.page || this.pageUI[i].totalPage!=this.pageCount){
					this.pageUI[i].setPagerData(this.pageCount,this.page);
				}
			}
		}
	},
	createPageUI:function(_pageUIBox){
		var pageUI = new FWK.UI.PagerUI(this.pageX,false,"&nbsp;总计：<span>$1</span>&nbsp;页");
		pageUI.$refreshPageContent = this.pageChange.bind(this);
		pageUI.setPagerData(this.pageCount,this.page);
		pageUI.renderTo(_pageUIBox);
		_pageUIBox = null;delete _pageUIBox;
		return pageUI;
	},
	writeToList:function(){
		FWK.Element.clearChild.call(this.writeBox);
		if (this.recordCount == 0) {
			try {
				FWK.Element.addChild.call(this.writeBox, this.$noTr());
				return ;
			}
			catch (e) {
			}
			return ;
		}
		if(this.xPaths.server){
			var recordArr = this.recordArr;
		}
		else{
			var recordArr = XN.toArray(this.recordArr).slice((this.page-1)*this.pageSize,this.page*this.pageSize);
		}

		for(var i=0,ilen=recordArr.length;i<ilen;i+=1){
			var tr = this.$makeTr(recordArr[i],i);
			if(tr)FWK.Element.addChild.call(this.writeBox,tr);
			tr = null;delete tr;
		}
		recordArr = null;
		delete recordArr;
		try{this.$writeOk();}catch(e){}
	},
	pageChange:function(_page){
		//_page = _page || this.pageUI.currentPage;
		if(this.xPaths.server){
			this.obj[this.pageName] = _page;
			try{this.$pageChange()}catch(e){};
			this.askForData();
		}
		else{
			this.page = _page;
			if(this.pageUI && FWK.isArr(this.pageUI)){
				for(var i=0;i<this.pageUI.length;i+=1){
					if(this.pageUI[i].currentPage!=this.page){
						this.pageUI[i].setPagerData(this.pageCount,this.page);
					}
				}
			}
			try{this.$pageChange()}catch(e){};
			this.writeToList();
		}
	},
	$makeTr:function(_xml,j){
		return FWK.createElement("div",{},j + "请重写makeTr此函数..." + (_xml.xml.replace(/</g,"&lt;")).replace(/>/g,"&gt;"));
	},
	$errData:function(_ret){
		if(this.$errTr){
			FWK.Element.clearChild.call(this.writeBox);
			FWK.Element.addChild.call(this.writeBox, this.$errTr(_ret.des,_ret.code));
		}
		else{
			alert(_ret.des);
		}
	},
	$loading:function(){
		FWK.Element.clearChild.call(this.writeBox);
		FWK.Element.addChild.call(this.writeBox, this.$loadTr());
	}
});